UML类图详解

您所在的位置:网站首页 uml中关联的多重性是指( ) UML类图详解

UML类图详解

2024-07-11 03:45| 来源: 网络整理| 查看: 265

首先先来明确一个概念,即多重性。什么是多重性呢?多重性是指两个对象之间的链接数目,表示法是“下限...上限”,最小数据为零(0),最大数目为没有设限(*),如果仅标示一个数目级上下限相同。

实际在UML中是可以隐藏上图中申购交易的细节

导航性(navigation):关联关系的细节信息通常放置于两关联端,像是关联端标示箭头,代表该关联端具有可导航性。

下面我们来看一个“多对一”的例子

Fund.h

1 class Fund 2 { 3 public: 4 void setPrice(float); 5 float getPrice(); 6 void setFee(float); 7 float getFee(); 8 private: 9 float price; 10 float fee; 11 };

Fund.cpp

1 #include "Fund.h" 2 3 void Fund::setPrice(float thePrice) 4 { 5 price=thePrice; 6 } 7 8 float Fund::getPrice() 9 { 10 return price; 11 } 12 13 void Fund::setFee(float theFee) 14 { 15 fee=theFee; 16 } 17 18 float Fund::getFee() 19 { 20 return fee; 21 }

Bid.h

1 #include "Fund.h" 2 3 class Bid 4 { 5 public: 6 float calcUnit(); 7 float calcFee(); 8 void setFund(Fund*); 9 void setAmount(int); 10 int getAmount(); 11 private: 12 int amount; 13 Fund *fundObj; 14 };

声明一个基金对象指针,此即为多重性为1的实现方法之一。然后类Bid中的函数setFund设计了一个公有操作,让外界可以传入基金对象的指针,也就建立起申购交易对象指向基金对象的链接了。

Bid.cpp

1 #include "Bid.h" 2 3 float Bid::calcUnit() 4 { 5 float thePrice, theUnit; 6 thePrice=fundObj->getPrice(); 7 theUnit=amount/thePrice; 8 return theUnit; 9 } 10 11 float Bid::calcFee() 12 { 13 float theFundFee, theFee; 14 theFundFee=fundObj->getFee(); 15 theFee=amount*theFundFee; 16 return theFee; 17 } 18 19 void Bid::setFund(Fund *theFund) 20 { 21 fundObj=theFund; 22 } 23 24 void Bid::setAmount(int theAmount) 25 { 26 amount=theAmount; 27 } 28 29 int Bid::getAmount() 30 { 31 return amount; 32 }

main.cpp

1 #include 2 #include 3 #include "Fund.h" 4 #include "Bid.h" 5 using namespace std; 6 7 int main(int argc, char *argv[]) 8 { 9 Fund myFund; 10 float thePrice, theFee; 11 Bid myBid; 12 int theAmount; 13 14 cout > thePrice; 16 myFund.setPrice(thePrice); 17 cout > theFee; 19 myFund.setFee(theFee); 20 21 cout > theAmount; 23 myBid.setAmount(theAmount); 24 myBid.setFund(&myFund); 25 26 cout


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3